const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const VueLoaderPlugin = require('vue-loader/lib/plugin');
module.exports = {
	mode: 'production',
	entry: {
		'inforCenter': [__dirname + "/src/pages/inforCenter/index.js"],
		'matchCenter': [__dirname + "/src/pages/matchCenter/index.js"],
		'QBi': [__dirname + "/src/pages/QBi/index.js"],
	},
	output: {
		path: __dirname + "/build",
		filename: './[name]/bundle.js',
	},
	module: {
		rules: [
			{
				test: /\.(vue)$/,
				loader: 'vue-loader',
			},
			{
				test: /\.json$/,
				loader: "json-loader"
			},
			{
				test: /\.js$/,
				exclude: /node_modules/,
				loader: 'babel-loader',
				query: {
					presets: ['es2015', 'stage-0'],
					plugins: ['transform-runtime']
				}
			},
			{
                test: /\.(eot|woff|woff2|ttf)([\\?]?.*)$/,
                loader: "file-loader"
            },
			{
				test: /\.(css|less)$/,
				use: [MiniCssExtractPlugin.loader, "css-loader", "postcss-loader", "less-loader",]
			},
			{
				test: /\.(png|jpg|gif|svg)$/,
				exclude: /node_modules/,
				loader: 'url-loader?limit=8192&name=images/[hash:8].[name].[ext]'
			}
		]
	},
	resolve: {
		alias: {
			'vue$': 'vue/dist/vue.esm.js'
		},
		extensions: ['.js', '.vue']
	},
	plugins: [
		new VueLoaderPlugin(),
		new HtmlWebpackPlugin({
			template: './src/pages/inforCenter/index.html',
			filename: 'inforCenter.html',
			inject: 'body',
			chunks: ['manifest', 'inforCenter', 'vendor', 'common']
		}),
		new HtmlWebpackPlugin({
			template: './src/pages/matchCenter/index.html',
			filename: 'matchCenter.html',
			inject: 'body',
			chunks: ['manifest', 'matchCenter', 'vendor', 'common']
		}),
		new HtmlWebpackPlugin({
			template: './src/pages/QBi/index.html',
			filename: 'QBi.html',
			inject: 'body',
			chunks: ['manifest', 'QBi', 'vendor', 'common']
		}),

		new MiniCssExtractPlugin({
			filename: "[name].[chunkhash:8].css",
			chunkFilename: "[id].css"
		}),
		new CleanWebpackPlugin(['build']),
		new webpack.DefinePlugin({
			'process.env': {
				NODE_ENV: '"production"'
			}
		}),
		new webpack.LoaderOptionsPlugin({
			minimize: true
		})
	],
	optimization: {
		runtimeChunk: {
			name: "manifest"
		},
		//拆分公共包
		splitChunks: {
			cacheGroups: {
				//项目公共组件
				common: {
					chunks: "initial",
					name: "common",
					minChunks: 2,
					maxInitialRequests: 5,
					minSize: 0
				},
				//第三方组件
				vendor: {
					test: /node_modules/,
					chunks: "initial",
					name: "vendor",
					priority: 10,
					enforce: true
				}
			}
		}
	},
	performance: {
		hints: false
	}
}
